package com.itheima.exam.web.result;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 定义默认的返回结果
 * {
 *     "code":200,
 *     "errMsg":"错误信息",
 *     "result":返回的结果
 * }
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private int code;
    private String errMsg;
    private T result;

    /**
     * 快速构建成功的Result对象
     */
    public static <T> Result OK(T result){
        return Result.builder().code(200).result(result).build();
    }
    /**
     * 快速构建失败的Result对象
     */
    public static <T> Result ERR(String errMsg){
        return Result.builder().code(400).errMsg(errMsg).build();
    }
}
